<?php require_once 'includes/preload.php'; ?>
<?php
$action=trim(request('action'));
$pagination=get('page');
$pageSize=3;
$listTitle='';
$visaListData=array();
$urlParameters=array();
//--
if($action){
    $urlParameters['action']=$action;
}
//--
switch($action) {
    case 'area':
        $area=$urlParameters['area']=get('area');
        if(is_numeric($area)){
            $listTitle=$db->getOne(sprintf('SELECT title FROM %s WHERE %s=%s',$db->Table('country'),'id',$area));
            $visaListData=$db->getLimit(sprintf('SELECT * FROM %s WHERE %s=%s',$db->Table('visa'),'country',$area),
                $pagination,
                $pageSize
            );
        }
        else{
            return;
        }
    break;
    case 'search':
        $keywords=$urlParameters['keywords']=urldecode(request('keywords'));
        if($keywords){
            $listTitle=$keywords;
            $visaListData=$db->getLimit(sprintf('SELECT * FROM %s WHERE types like ? ORDER BY id DESC',$db->Table('visa')),
                $pagination,
                $pageSize,
                array(
                    '%'.$keywords.'%'
                )
            );
        }
        else{
            echo '请输入查询关键字。';
            return;
        }
    break;
    default:
        $listTitle='签证';
        $visaListData=$GLOBALS['db']->getLimit(sprintf('SELECT * FROM %s ORDER BY %s DESC',$db->Table('visa'),'id'),
            $pagination,
            $pageSize
        );
        //#return;
}